﻿namespace HuaWei
{
    using HuaWei.CommClass;
    using HuaWei.DAI;
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;

    public class BusinessManager
    {
        private DateTime _UpdateTime;
        [CompilerGenerated]

        private IDataAccess _Ida;

        public BusinessManager()
        {
            this._UpdateTime = DateTime.Now;
        }

        public string RobackDataValidate(string param)
        {
            List<string> list = CHelp.ParamToList(param);
            string jgid = list[0];
            string bdid = list[1];
            int qcid = Convert.ToInt32(list[2]);
            string sql = "";
            IDataAccess ida = this._ida;
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and SJID='{1}' and Convert(int,qcid) > {2}", bdid, jgid, qcid);
            DataTable table = DBHelp.GetDt(ida, sql, "JGSCRZ");
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["SFHQ"].Equals(1))
                {
                    return "请先退回后面的期次！";
                }
            }
            return "";
        }

        public string CancelUpdate(string param)
        {
            List<string> list = CHelp.ParamToList(param);
            string str = list[0];
            string str2 = list[1];
            string str3 = list[2];
            string sql = "";
            IDataAccess ida = this._ida;
            List<TableInfo> list2 = SysDtManager.IniJLTableList();
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and JGID='{1}' and qcid='{2}'", str2, str, str3);
            DataTable table = DBHelp.GetDt(ida, sql, "JGSCRZ");
            sql = string.Format("select MC from ZZJGXX where JGLX=0 and LEN(levelCode)=3 and ID='{0}'", str);
            bool flag = DBHelp.GetDt(ida, sql, "ZZJGXX").Rows.Count > 0;
            if (table.Rows.Count > 0)
            {
                if (!(flag || !table.Rows[0]["SFHQ"].Equals(1)))
                {
                    return "ERROR: 你提交的数据已被其它机构获取，请通知获取数据的机构退回本期数据再继续当前操作";
                }
                ArrayList sqlList = new ArrayList();
                foreach (TableInfo info in list2)
                {
                    sql = string.Format("delete from {0}2 where bdid='{1}' and sid='{2}' and qcid='{3}'", new object[] { info.TableName, str2, str, str3 });
                    sqlList.Add(sql);
                }
                sql = string.Format("delete from JGSCRZ where bdid='{0}' and JGID='{1}' and qcid='{2}'", str2, str, str3);
                sqlList.Add(sql);
                sql = string.Format("update XMQC set zt=-1 where bdid='{0}' and qcid='{1}'", str2, str3);
                sqlList.Add(sql);
                this.DelRepData(sqlList, str2, str3);
                ida.ExecuteNonQuery(sqlList, CommandType.Text);
                SysManager.WriteLog("CancelUpdate OK");
                return "";
            }
            return "ERROR: 当期没有可撤回的数据！";
        }

        public DataSet CheckUser(string param)
        {
            List<string> list = CHelp.ParamToList(param);
            string str = list[0];
            string str2 = list[1];
            string str3 = list[2];
            DataSet ds = new DataSet();
            IDataAccess ida = this._ida;
            string sql = string.Format("select a.*,b.jglx as JGLX from YHXX a left join ZZJGXX b on a.bdid=b.id where a.yhmc='{0}' and a.yhmm='{1}'", str, str2);
            DBHelp.SetDs(ds, sql, "YHXX", ida);
            DataTable table = ds.Tables["YHXX"];
            if (table.Rows.Count > 0)
            {
                DataRow row = table.Rows[0];
                string str5 = row["KHDBJ"].ToString();
                if (str5.Equals(""))
                {
                    sql = string.Format("update YHXX set khdbj='{0}' where yhmc='{1}' and yhmm='{2}'", str3, str, str2);
                    DBHelp.ExeSql(ida, sql);
                }
                else if (!str5.Equals(str3))
                {
                    return null;
                }
            }
            return ds;
        }

        private void DelRepData(ArrayList sqlList, string bdid, string qcid)
        {
            string str = string.Format("delete from {0} where bdid='{1}' and qcid={2}", "REP_ZQZFZS", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid={2}", "REP_ZQJKZF1", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid={2}", "REP_ZQJKZF2", bdid, qcid);
            sqlList.Add(str);
            str = string.Format("delete from {0} where bdid='{1}' and qcid={2}", "REP_GCBG", bdid, qcid);
            sqlList.Add(str);
        }

        public DataSet GetAllData(DataSet dsRequest, string loginId)
        {
            IDataAccess ida = this._ida;
            string sql = "";
            DataTable table = DBHelp.GetDt(ida, string.Format("select * from ZZJGXX where id='{0}'", loginId), "ZZJGXX");
            if (table.Rows.Count > 0)
            {
                try
                {
                    DataSet dsResult = new DataSet();
                    string str2 = table.Rows[0]["LevelCode"].ToString();
                    string str3 = table.Rows[0]["xmid"].ToString();
                    string bdidsSql = string.Format("select id from zzjgxx where levelCode like '{0}%' and xmid='{1}'", str2, str3);
                    string str5 = str2.Substring(0, 3);
                    DHelp.GetFieldValue(DBHelp.GetDt(ida, string.Format("select * from ZZJGXX where levelCode='{0}' and xmid='{1}'", str5, str3), "yzxx"), "id", 0);
                    table.Rows[0]["jglx"].ToString();
                    string updateTime = "2015-01-01";
                    string bdid = "";
                    string qcid = "";
                    string tableName = "";
                    this.GetGXJGUpdateData(ida, dsRequest, dsResult, loginId, updateTime, str3, str2, bdidsSql);
                    sql = string.Format("select * from xmqc where xmid='{0}' and bdid in (select id from zzjgxx where levelCode like '{1}%'  and xmid='{0}') order by BDID,QCID", str3, str5);
                    DataTable table3 = DBHelp.GetDt(ida, sql, "xmqc-t");
                    if (table3.Rows.Count > 0)
                    {
                        List<TableInfo> list = SysDtManager.IniJLTableList();
                        foreach (DataRow row in table3.Rows)
                        {
                            bdid = row["bdid"].ToString();
                            qcid = row["qcid"].ToString();
                            if (row["zt"].Equals(1))
                            {
                                foreach (TableInfo info in list)
                                {
                                    this.SetAllJlDt(ida, dsResult, info.TableName + "2", bdid, qcid);
                                }
                                sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "XMQC", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "XMQC", ida);
                                sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQZFZS", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "REP_ZQZFZS", ida);
                                sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF1", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "REP_ZQJKZF1", ida);
                                sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF2", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "REP_ZQJKZF2", ida);
                                sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_GCBG", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "REP_GCBG", ida);
                            }
                            else
                            {
                                foreach (TableInfo info in list)
                                {
                                    tableName = info.TableName + "2";
                                    sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}' and sid in (select id from zzjgxx where levelCode like '{3}%'  and xmid='{4}')", new object[] { tableName, bdid, qcid, str2, str3 });
                                    DBHelp.SetDs(dsResult, sql, tableName, ida);
                                }
                                sql = string.Format("select * from XMQC where bdid='{0}' and qcid='{1}'", bdid, qcid);
                                DBHelp.SetDs(dsResult, sql, "XMQC", ida);
                            }
                        }
                        sql = "select * from JGSCRZ";
                        DBHelp.SetDs(dsResult, sql, "JGSCRZ", ida);
                    }
                    return dsResult;
                }
                catch (Exception exception)
                {
                    Log.Write(exception.Message);
                    ida.RollBack();
                    return null;
                }
            }
            return null;
        }

        private void GetGXJGUpdateData(IDataAccess ida, DataSet dsRequest, DataSet dsResult, string loginId, string updateTime, string xmid, string levelCode, string bdidsSql)
        {
            string sql = string.Format("select * from {0}", "XMJBXX");
            DBHelp.SetDs(dsResult, sql, "XMJBXX", ida);
            this.SetDtByTime(ida, dsResult, updateTime, "XMJBXXEX", "id", xmid, false);
            if (!levelCode.Equals(""))
            {
                string str2 = levelCode.Substring(0, 3);
                string str3 = string.Format("select id from zzjgxx where levelCode like '{0}%' and xmid='{1}'", str2, xmid);
                this.SetDtByTime(ida, dsResult, updateTime, "ZZJGXX", "id", str3, true);
                this.SetDtByTime(ida, dsResult, updateTime, "ZZJGXXEX", "id", str3, true);
            }
            sql = string.Format("select * from {0} where bdid in ({1}) or bdid='-1'", "CTFL", bdidsSql);
            DBHelp.SetDs(dsResult, sql, "CTFL", ida);
            sql = string.Format("select * from {0} where bdid in ({1}) or bdid='-1'", "GCLCT", bdidsSql);
            DBHelp.SetDs(dsResult, sql, "GCLCT", ida);
            this.SetDtByTime(ida, dsResult, updateTime, "JLQD", "bdid", bdidsSql, true);
            this.SetDtByTime(ida, dsResult, updateTime, "CLQD", "bdid", bdidsSql, true);
            //this.SetDtByTime(ida, dsResult, updateTime, "GCLCT", "1", "1", false);
            this.SetDtByTime(ida, dsResult, updateTime, "BGL", "bdid", bdidsSql, true);
            this.SetDtByTime(ida, dsResult, updateTime, "BGLQD", "bdid", bdidsSql, true);
        }

        private void GetJlUpdateData(IDataAccess ida, DataSet dsRequest, DataSet dsResult, DataRow rowParam, string levelCode, string xmid)
        {
            string sql = "";
            List<TableInfo> list = SysDtManager.IniJLTableList();
            string bdid = "";
            string qcid = "";
            bdid = rowParam["bdid"].ToString();
            qcid = rowParam["qcid"].ToString();
            foreach (TableInfo info in list)
            {
                this.method(ida, dsResult, info.TableName + "2", bdid, qcid, levelCode, xmid);
            }
            sql = string.Format("select * from XMQC where bdid='{0}' and qcid='{1}'", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "XMQC", ida);
        }

        public DataSet GetUpdateData(DataSet dsRequest, string loginId)
        {
            IDataAccess ida = this._ida;
            this.SetUpdateTime();
            string sql = "";
            DataTable table = DBHelp.GetDt(ida, string.Format("select * from ZZJGXX where id='{0}'", loginId), "ZZJGXX");
            if (table.Rows.Count > 0)
            {
                try
                {
                    ida.BeginTrans();
                    DataSet dsResult = new DataSet();
                    string str2 = table.Rows[0]["LevelCode"].ToString();
                    string str3 = table.Rows[0]["xmid"].ToString();
                    string bdidsSql = string.Format("select id from zzjgxx where levelCode like '{0}%' and xmid='{1}'", str2, str3);
                    string str5 = str2.Substring(0, 3);
                    string yzid = DHelp.GetFieldValue(DBHelp.GetDt(ida, string.Format("select * from ZZJGXX where levelCode='{0}' and xmid='{1}'", str5, str3), "yzxx"), "id", 0);
                    DataTable table3 = DBHelp.GetDt(ida, string.Format("select * from ClientUpdateTime where LoginId='{0}'", loginId), "ClientUpdateTime");
                    string updateTime = "";
                    if (table3.Rows.Count > 0)
                    {
                        updateTime = table3.Rows[0]["updateTime"].ToString();
                    }
                    this.GetGXJGUpdateData(ida, dsRequest, dsResult, loginId, updateTime, str3, str2, bdidsSql);
                    sql = string.Format("select * from JGSCRZ where ((sfhq=0 and sjId='{0}') or (sjId='' and jgid='" + yzid + "')) and updateTime < '{1}'", loginId, this._UpdateTime.ToString());
                    DataTable table4 = DBHelp.SetDs(dsResult, sql, "JGSCRZ", ida);
                    if (table4.Rows.Count > 0)
                    {
                        foreach (DataRow row in table4.Rows)
                        {
                            if (row["sjId"].Equals(""))
                            {
                                //if (!row["jgid"].Equals(loginId) && !updateTime.Equals(""))
                                //{
                                DateTime time = (DateTime)row["UpdateTime"];
                                if (!updateTime.Equals("") && CHelp.ConverDateTime(updateTime, false) < time)
                                {
                                    this.GetYzUpdateData(ida, dsRequest, dsResult, row, loginId, str2, str3);
                                }
                                //}
                            }
                            else
                            {
                                this.GetJlUpdateData(ida, dsResult, dsResult, row, str2, str3);
                            }
                        }
                    }
                    ida.Commit();
                    return dsResult;
                }
                catch (Exception exception)
                {
                    Log.Write(exception.Message);
                    ida.RollBack();
                    return null;
                }
            }
            return null;
        }

        private void GetYzUpdateData(IDataAccess ida, DataSet dsRequest, DataSet dsResult, DataRow dataRow, string loginId, string levelCode, string xmid)
        {
            string sql = "";
            string bdid = dataRow["bdid"].ToString();
            string qcid = dataRow["qcid"].ToString();
            foreach (TableInfo info in SysDtManager.IniJLTableList())
            {
                this.SetYzJlDt(ida, dsResult, info.TableName + "2", bdid, qcid, levelCode, xmid);
            }
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "XMQC", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "XMQC", ida);
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQZFZS", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "REP_ZQZFZS", ida);
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF1", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "REP_ZQJKZF1", ida);
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_ZQJKZF2", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "REP_ZQJKZF2", ida);
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", "REP_GCBG", bdid, qcid);
            DBHelp.SetDs(dsResult, sql, "REP_GCBG", ida);
        }

        private void method(IDataAccess ida, DataSet ds, string tableName, string bdid, string qcid, string jgLevelCode, string xmid)
        {
            string sql = "";
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}' and sid in (select id from zzjgxx where levelCode != '{3}' and levelCode like '{3}%' and xmid='{4}')", new object[] { tableName, bdid, qcid, jgLevelCode, xmid });
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        private void method1(IDataAccess ida, DataSet ds, DataTable dt, bool isYZ, string bdid, string qcid)
        {
            string sql = "";
            DataTable tDt = DBHelp.SetDt(ds, "XMQC", "1=2", ida);
            if (tDt != null)
            {
                string[] strArray2;
                object[] objArray2;
                sql = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", dt.TableName, bdid, qcid);
                DBHelp.ExeSql(ida, sql);
                if (!isYZ)
                {
                    strArray2 = new string[] { "zt" };
                    objArray2 = new object[] { -1 };
                    DHelp.CopyDt(dt, tDt, strArray2, objArray2);
                }
                else
                {
                    strArray2 = new string[] { "zt" };
                    objArray2 = new object[] { 1 };
                    DHelp.CopyDt(dt, tDt, strArray2, objArray2);
                }
            }
        }

        public DataSet method2()
        {
            IDataAccess ida = this._ida;
            DataSet ds = new DataSet();
            string sql = string.Format("select * from {0}", "XMJBXX");
            DBHelp.SetDs(ds, sql, "XMJBXX", ida);
            return ds;
        }

        private void method3(DataTable dt, DataTable tDt)
        {
            foreach (DataRow row in dt.Rows)
            {
                DataRow row2;
                DataRow[] rowArray = tDt.Select("id='" + row["id"].ToString() + "'");
                if (rowArray.Length == 0)
                {
                    row2 = tDt.NewRow();
                    row2["id"] = row["id"];
                    DHelp.CopyRow(row, row2, "", "");
                    tDt.Rows.Add(row2);
                }
                else
                {
                    row2 = rowArray[0];
                    DHelp.CopyRow(row, row2, "", "#khdbj#updatetime#");
                }
            }
        }

        public string ModifyUpdateStatus(string param)
        {
            string str = CHelp.ParamToList(param)[0];
            try
            {
                string str2;
                this._ida.BeginTrans();
                str2 = string.Format("update JGSCRZ set sfhq=1 where sfhq=0 and sjId='{0}' and updateTime < '{1}'", str, this._UpdateTime.ToString());
                DBHelp.ExeSql(this._ida, str2);
                DataSet ds = new DataSet();
                DataTable table = DBHelp.SetDs(ds, string.Format("select * from ClientUpdateTime where LoginId='{0}'", str), "ClientUpdateTime", this._ida);
                if (table.Rows.Count.Equals(0))
                {
                    DataRow row = table.NewRow();
                    row["id"] = Guid.NewGuid();
                    row["LoginId"] = str;
                    row["updateTime"] = this._UpdateTime;
                    row.EndEdit();
                    table.Rows.Add(row);
                }
                else
                {
                    table.Rows[0]["updateTime"] = this._UpdateTime;
                }
                this._ida.Update(ds, true);
                this._ida.Commit();
            }
            catch (Exception exception)
            {
                this._ida.RollBack();
                Log.Write(exception.Message);
            }
            return "";
        }

        public string RobackData(string param)
        {
            List<string> list = CHelp.ParamToList(param);
            string str = list[0];
            string str2 = list[1];
            string str3 = list[2];
            string sql = "";
            IDataAccess ida = this._ida;
            new DataSet();
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and jgid='{1}' and qcid='{2}'", str2, str, str3);
            if (DBHelp.GetDt(ida, sql, "JGSCRZ").Rows.Count > 0)
            {
                return "ERROR: 你已上传当前数据，请撤销后再执行退回操作！";
            }
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and SJID='{1}' and qcid='{2}'", str2, str, str3);
            DataTable table2 = DBHelp.GetDt(ida, sql, "JGSCRZ");
            if (table2.Rows.Count > 0)
            {
                if (table2.Rows[0]["SFHQ"].Equals(0))
                {
                    return "ERROR: 当前没有可退回的数据，如有问题请与管理员联系！";
                }
                sql = string.Format("update JGSCRZ set SFHQ=2 where bdid='{0}' and SJID='{1}' and qcid='{2}'", str2, str, str3);
                ida.ExecuteNonQuery(sql, CommandType.Text);
            }
            SysManager.WriteLog("RobackData OK");
            return "";
        }

        private void SetAllJlDt(IDataAccess ida, DataSet ds, string tableName, string bdid, string qcid)
        {
            string sql = "";
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}'", tableName, bdid, qcid);
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        private void SetDt(IDataAccess ida, DataSet ds, string sql, string tableName)
        {
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        private void SetDtByTime(IDataAccess ida, DataSet ds, string updateTime, string tableName, string fieldName, string value, [Optional, DefaultParameterValue(true)] bool isIn)
        {
            string sql = "";
            if (isIn)
            {
                if (!value.Equals(""))
                {
                    sql = string.Format("select * from {0} where updateTime >= '{1}' and {2} in ({3})", new object[] { tableName, updateTime, fieldName, value });
                }
                else
                {
                    sql = string.Format("select * from {0} where updateTime >= '{1}'", tableName, updateTime);
                }
            }
            else
            {
                sql = string.Format("select * from {0} where updateTime >= '{1}' and {2}='{3}'", new object[] { tableName, updateTime, fieldName, value });
            }
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        private void SetJlDt(IDataAccess ida, DataSet ds, string tableName, string bdid, string qcid, string jgid)
        {
            string sql = "";
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}' and sid='{3}'", new object[] { tableName, bdid, qcid, jgid });
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        public void SetUpdateTime()
        {
            this._UpdateTime = DateTime.Now;
        }

        private void SetYzJlDt(IDataAccess ida, DataSet ds, string tableName, string bdid, string qcid, string jgLevelCode, string xmid)
        {
            string sql = "";
            sql = string.Format("select * from {0} where bdid='{1}' and qcid='{2}' and sid in (select id from zzjgxx where (levelCode not like '{3}%' or levelCode='{3}') and xmid='{4}')", new object[] { tableName, bdid, qcid, jgLevelCode, xmid });
            DBHelp.SetDs(ds, sql, tableName, ida);
        }

        public string UnLock(string param)
        {
            List<string> list = CHelp.ParamToList(param);
            string str = list[0];
            string str2 = list[1];
            string str3 = list[2];
            string sql = "";
            IDataAccess ida = this._ida;
            new DataSet();
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and jgid='{1}' and qcid='{2}'", str2, str, str3);
            if (DBHelp.GetDt(ida, sql, "JGSCRZ").Rows.Count == 0)
            {
                return "ERROR: 当前数据未导出！";
            }
            sql = string.Format("select * from JGSCRZ where bdid='{0}' and SJID='' and qcid='{2}'", str2, str, str3);
            if (DBHelp.GetDt(ida, sql, "JGSCRZ").Rows.Count > 0)
            {
                sql = string.Format("update JGSCRZ set SFHQ=0 where bdid='{0}' and SJID='{1}' and qcid='{2}'", str2, str, str3);
                ida.ExecuteNonQuery(sql, CommandType.Text);
            }
            SysManager.WriteLog("UnLock OK");
            return "";
        }

        public string UpdateJLData(DataSet dsSource, string param)
        {
            if (dsSource.Tables.Count > 0)
            {
                IDataAccess ida = this._ida;
                List<string> list = CHelp.ParamToList(param);
                string str = list[0];
                string str2 = list[1];
                string str3 = list[2];
                bool isYZ = false;
                ida.OpenDatabase();
                try
                {
                    DataSet ds = new DataSet();
                    string sql = string.Format("select * from JGSCRZ where bdid='{0}' and JGID='{1}' and qcid='{2}'", str2, str, str3);
                    DataTable table = DBHelp.SetDs(ds, sql, "JGSCRZ", ida);
                    if (table.Rows.Count > 0)
                    {
                        return "ERROR: 数据已上传,如有问题请与管理员联系。";
                    }
                    sql = string.Format("select * from ZZJGXX where id='{0}'", str);
                    DataTable dt = DBHelp.GetDt(ida, sql, "SJJG");
                    string str6 = DHelp.GetFieldValue(dt, "LevelCode", 0);
                    CHelp.ConvertInt(DHelp.GetFieldValue(dt, "jglx", 0), 0);
                    isYZ = str6.Length.Equals(3);
                    string str7 = "";
                    if (!isYZ)
                    {
                        str7 = DHelp.GetFieldValue(dt, "pid", 0);
                    }
                    DataRow row = table.NewRow();
                    row["id"] = Guid.NewGuid();
                    row["BDID"] = str2;
                    row["JGID"] = str;
                    row["QCID"] = str3;
                    row["SJID"] = str7;
                    row["SFHQ"] = 0;
                    row.EndEdit();
                    table.Rows.Add(row);
                    ida.BeginTrans();
                    foreach (DataTable table3 in dsSource.Tables)
                    {
                        if (table3.Rows.Count > 0)
                        {
                            sql = string.Empty;
                            string tableName = table3.TableName;
                            if (tableName.Equals("XMQC"))
                            {
                                this.method1(ida, ds, table3, isYZ, str2, str3);
                            }
                            else if (((tableName.Equals("REP_ZQZFZS") || tableName.Equals("REP_ZQJKZF1")) || tableName.Equals("REP_ZQJKZF2")) || tableName.Equals("REP_GCBG"))
                            {
                                DataTable tDt = DBHelp.SetDt(ds, tableName, "1=2", ida);
                                sql = string.Format("delete from {0} where bdid='{1}' and qcid='{2}'", table3.TableName, str2, str3);
                                DHelp.CopyDt(table3, tDt);
                            }
                            else if (tableName.Equals("CTFL") || tableName.Equals("gclct"))
                            {
                                DataTable tDt = DBHelp.SetDt(ds, tableName, "1=2", ida);
                                sql = string.Format("delete from {0} where bdid='{1}'", table3.TableName, str2);
                                DHelp.CopyDt(table3, tDt);
                            }
                            else
                            {
                                DataTable table5 = DBHelp.SetDt(ds, tableName + "2", "1=2", ida);
                                if (table5 != null)
                                {
                                    string[] strArray2;
                                    object[] objArray2;
                                    if (!isYZ)
                                    {
                                        sql = string.Format("delete from {0}2 where bdid='{1}' and qcid='{2}' and sid='{3}'", new object[] { table3.TableName, str2, str3, str });
                                        strArray2 = new string[] { "sid", "tysb", "spzt" };
                                        objArray2 = new object[] { str, 0, -1 };
                                        DHelp.CopyDt(table3, table5, strArray2, objArray2);
                                    }
                                    else
                                    {
                                        strArray2 = new string[] { "sid", "tysb", "spzt" };
                                        objArray2 = new object[] { str, 1, 0 };
                                        sql = string.Format("delete from {0}2 where bdid='{1}' and qcid='{2}' and sid='{3}'", new object[] { table3.TableName, str2, str3, str });
                                        DHelp.CopyDt(table3, table5, strArray2, objArray2);
                                    }
                                }
                            }
                            if (!string.IsNullOrEmpty(sql))
                            {
                                DBHelp.ExeSql(ida, sql);
                            }
                        }
                    }
                    ida.Update(ds, true);
                    ida.Commit();
                }
                catch (Exception exception)
                {
                    ida.RollBack();
                    throw exception;
                }
                finally
                {
                    ida.CloseDatabase();
                }
            }
            return "";
        }

        public string UpdateXMData(DataSet dsSource, string param)
        {
            IDataAccess ida = this._ida;
            string local1 = CHelp.ParamToList(param)[0];
            string sql = "";
            ida.OpenDatabase();
            try
            {
                DataSet ds = new DataSet();
                ida.BeginTrans();
                foreach (DataTable table in dsSource.Tables)
                {
                    DataTable table2;
                    string tableName = table.TableName;
                    if (!tableName.Equals("YHXX"))
                    {
                        table2 = DBHelp.SetDt(ds, tableName, "1=2", ida);
                        if (table2 != null)
                        {
                            sql = string.Format("delete from {0}", table.TableName);
                            DBHelp.ExeSql(ida, sql);
                            DHelp.CopyDt(table, table2);
                        }
                    }
                    else
                    {
                        table2 = DBHelp.SetDt(ds, tableName, "1=1", ida);
                        this.method3(table, table2);
                    }
                }
                ida.Update(ds, true);
                ida.Commit();
                SysManager.WriteLog("UpdateXMData OK");
            }
            catch (Exception exception)
            {
                Log.Write(DateTime.Now.ToString() + ":" + exception.Message);
                ida.RollBack();
                throw exception;
            }
            finally
            {
                ida.CloseDatabase();
            }
            return "";
        }

        public string UpdateXMData_old(DataSet dsSource, string param)
        {
            IDataAccess ida = this._ida;
            string local1 = CHelp.ParamToList(param)[0];
            string sql = "";
            string str2 = "";
            ida.OpenDatabase();
            try
            {
                DataSet ds = new DataSet();
                ida.BeginTrans();
                foreach (DataTable table in dsSource.Tables)
                {
                    string tableName = table.TableName;
                    DataTable tDt = DBHelp.SetDt(ds, tableName, "1=2", ida);
                    if (tDt != null)
                    {
                        str2 = DHelp.GetIds(table, "id", "");
                        sql = string.Format("delete from {0} where id in ({1})", table.TableName, str2);
                        DBHelp.ExeSql(ida, sql);
                        DHelp.CopyDt(table, tDt);
                    }
                }
                ida.Update(ds, true);
                ida.Commit();
                SysManager.WriteLog("UpdateXMData OK");
            }
            catch (Exception exception)
            {
                Log.Write(DateTime.Now.ToString() + ":" + exception.Message);
                ida.RollBack();
                throw exception;
            }
            finally
            {
                ida.CloseDatabase();
            }
            return "";
        }

        public IDataAccess _ida
        {
            get
            {
                return this._Ida;
            }
            set
            {
                this._Ida = value;
            }
        }
    }
}

